<template>
	<view>
		<an-nav-bar title="上门服务"> </an-nav-bar>
		<view class="tabbar_top">
			<view class="param_search">
				<view class="param_item flex" @click="sortFilter = !sortFilter;serviceFilter=false;whereFilter=false;">
					<text class="text">{{sortText}}</text>
					<text class="iconfont icon-caret-down"></text>
					<view class="filter-box" :class="{'active-filter-box':sortFilter}"
						@touchmove.stop.prevent="moveHandle">
						<view class="filter-cnt">
							<view :class="{'check-text':orderByColumn == text.orderByColumn}"
								@click.stop="onSort(text.orderByColumn,text.isAsc)" v-for="(text,idx) in sortList"
								:key="idx">
								{{text.text}}
							</view>
						</view>
					</view>
				</view>
				<view class="param_item flex" @click="serviceFilter = !serviceFilter;sortFilter=false;whereFilter=false;">
					<text class="text">服务商</text>
					<text class="iconfont icon-caret-down"></text>
					<view class="filter-box" :class="{'active-filter-box':serviceFilter}"
						@touchmove.stop.prevent="moveHandle">
						<view class="service-cnt">
							<scroll-view class="scroll-view" scroll-y="true">
								<view class="scroll-view-item " :class="{'item-check':form.storeId == item.accountId}"
									v-for="(item,index) in shopList" :key="index" @click.stop="form.storeId=item.accountId;serviceFilter = false;getList();">
									{{item.storeName}}
								</view>
							</scroll-view>
							<!-- <view class="btn flex">
								<view @click.stop="serviceItem(1)">重置</view>
								<view @click.stop="serviceItem(2)">确认</view>
							</view> -->
						</view>
					</view>
				</view>
				<view class="screen flex_center " @click="whereFilter = !whereFilter;sortFilter=false;serviceFilter=false;" >
					<text>筛选</text>
					<text class="iconfont icon-shaixuan"></text>
					<view class="filter-box" :class="{'active-filter-box':whereFilter}"
						@touchmove.stop.prevent="moveHandle" @click.stop="">
						<view class="where-cnt">
							<view class="sort-where">
								<view class="line">
									<view class="title">价格区间</view>
									<view class="lbls flex">
										<input type="number" v-model="form.priceMin" @click.stop="">
										<view class=""></view>
										<input type="number" v-model="form.priceMax" @click.stop="">
									</view>
								</view>
								<view class="line">
									<view class="title">服务时长</view>
									<view class="lbls flex">
										<input type="number" v-model="form.serviceTimeMin" @click.stop="">
										<view class=""></view>
										<input type="number" v-model="form.serviceTimeMax" @click.stop="">
									</view>
								</view>
								<view class="btns flex_center">
									<button @click.stop="whereReset();getList()">重置</button>
									<button @click.stop="confirmWhere">确定</button>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- <view class="category">
			<view class="item" v-for="(item,idx) in categoryList" :key="idx" @click="serviceClass(item)">
				<view class="icon">
					<image :src="item.imgUrl" mode=""></image>
				</view>
				<view class="name">{{item.classifyName}}</view>
			</view>
		</view> -->
		<view style="height: 98rpx;"></view>
		<view class="project-list" v-if="projectList.length">
			<view class="item flex" v-for="(item,index) in projectList" :key="index" @click="gotoUrl(item)">
				<view class="photo">
					<image class="img" :src="$common.binImage(item.projectImg)" mode="">
					</image>
				</view>
				<view class="info">
					<view class="row flex">
						<view class="name">{{item.projectName}}</view>
						<!-- <view class="star flex">
							<i v-for="(item,index) in 5" :key="index"></i>
						</view> -->
					</view>
					<view class="row flex">
						<view class="time">服务时长：{{item.serviceTime}}分钟</view>
					</view>
					<view class="row flex">
						<view class="price flex">
							<span class="span1">{{item.sellPrice}}</span>
							<span class="span2">元/次</span>
						</view>
						<view class="order">已售{{item.sellNum}}份</view>
					</view>
					<view class="row flex">
						<view class="store flex">
							{{item.storeName}}
						</view>
					</view>
					<view class="row" style="display: none;">
						<view style="height: 60rpx; line-height: 60rpx; color: #999; overflow: hidden;">
							{{item.projectDesc}}
						</view>
						<!-- <view class="body flex">
							<view class="part" v-for="(lab,i) in labsList" :key="i" v-if="i < 5">{{lab}}</view>
						</view> -->
					</view>
				</view>
			</view>
		</view>
		<view class="project-list" v-if="!projectList.length">
			<view class="null-box">
				<image src="/static/null.png" mode=""></image>
				<view class="">列表为空</view>
			</view>
		</view>
	</view>
</template>

<script>
	import indexConfig from '@/config/index.config';
	export default {
		data() {
			return {
				orderByColumn: "",
				isSearch: false,
				sortFilter: false,
				serviceFilter: false,
				whereFilter: false,
				projectList: [],
				shopList: [],
				categoryList: [],
				labsList: [],
				form: {
					storeId:'',
				},
				sortList: [{
					text: '综合排序',
					orderByColumn: '',
					isAsc: ''
				}, {
					text: '订单最多',
					orderByColumn: 't.sell_num',
					isAsc: 'desc'
				}, {
					text: '距离最近',
					orderByColumn: 't.distance',
					isAsc: 'desc'
				}, {
					text: '最近加入',
					orderByColumn: 't.create_time',
					isAsc: 'desc'
				}, {
					text: '评分最高',
					orderByColumn: 't.score',
					isAsc: 'desc'
				}],
			};
		},
		onLoad() {
			this.$http.get('/appNoAuth/store/massageTechnician/listStore', {
				accountType: 2,
				status: 1
			}).then(res => {
				this.shopList = res.rows.map(val => {
					return {
						...val,
						check: false
					}
				})
			})
			this.$http.get('/appNoAuth/store/serviceProject/listServiceLabels', {}).then(res => {
				if (res.data) {
					this.labsList = res.data.split(',')
				}
			})
			// this.$http.get('/appNoAuth/store/serviceClassify/list', {}).then(res => {
			// 	this.categoryList = res.rows.map(val => {
			// 		return {
			// 			...val,
			// 			imgUrl: indexConfig.imgUrl + val.classifyImg
			// 		}
			// 	})
			// 	this.form.serviceClassifyId = this.categoryList[0].id
			// })
			
			this.whereReset()
			this.getList()
		},
		computed: {
			sortText() {
				let arr = this.sortList.filter(item => item.orderByColumn == this.orderByColumn)
				return arr[0].text
			}
		},
		methods: {
			gotoUrl(item) {
				uni.navigateTo({
					url: '/pages/projectDetails/projectDetails?id=' + item.id
				})
			},
			serviceClass(item){
				this.projectList = []
				this.form.serviceClassifyId = item.id
				this.getList()
			},
			serviceItem(idx) {
				if (idx == 1) {
					this.form.storeId = ''
				}
				this.serviceFilter = false
				this.getList()
			},
			onSort(t1, t2) {
				this.orderByColumn = t1
				this.form = {
					...this.form,
					orderByColumn: t1,
					isAsc: t2
				}
				this.getList()
				this.sortFilter = false
			},
			whereReset() {
				let {
					location
				} = this.$mStore.state
				
				this.form.storeId = ""
				this.form.serviceTimeMax = ""
				this.form.serviceTimeMin = ""
				this.form.priceMin = ""
				this.form.priceMax = ""
				this.form.serviceClassifyId = ""
				this.form.latitude = location.latitude
				this.form.longitude = location.longitude
				
				this.whereFilter = false
			},
			confirmWhere() {
				this.whereFilter = false
				this.getList()
			},
			onSearch() {
				this.isSearch = !this.isSearch
			},
			moveHandle() {
				return true
			},
			getList() {
				this.$http.get('/appNoAuth/store/serviceProject/list', this.form).then(res => {
					this.projectList = res.rows
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.project-list {
		width: 100%;
		background-color: #f8f8f8;

		.item {
			width: 100%;
			padding: 20rpx;
			box-sizing: border-box;
			background-color: #fff;
			margin-bottom: 10rpx;
			align-items: flex-start !important;

			.photo {
				width: 230rpx;
				height: 230rpx;
				margin-right: 30rpx;

				.img {
					width: 230rpx;
					height: 230rpx;
					border-radius: 10rpx;
					box-shadow: 0 0 6rpx 0 hsla(0, 0%, 40%, .28);
				}
			}

			.info {
				width: 450rpx;
				height: 230rpx;

				// .row {
				// 	margin-bottom: 8rpx;

				// }

				.name {
					max-width: 300rpx;
					overflow: hidden;
					font-size: 28rpx;
					color: #444;
					flex: 1;
					font-weight: 700;
				}

				.star {
					height: 30rpx;

					i {
						width: 28rpx;
						height: 30rpx;
						margin-left: 2rpx;
						background: url(/static/star.png) no-repeat 50%;
						background-size: 28rpx 26rpx;
					}
				}

				.time {
					color: #666;
					font-size: 24rpx;
				}

				.price {
					color: #e02020;
					font-size: 11px;
					flex: 1;

					.span1 {
						font-size: 34rpx;
						font-weight: 700;
					}

					.span2 {
						font-weight: 400;
						padding-left: 10rpx;
					}
				}

				.order {
					color: #666;
					font-size: 24rpx;
				}

				.store {
					font-size: 26rpx;
					color: #666;

					&::before {
						content: "";
						display: block;
						width: 26rpx;
						height: 24rpx;
						background: url(/static/shop-icon.png) no-repeat;
						background-size: 100% auto;
						margin-right: 6rpx;
					}
				}

				.body {
					margin-top: 6rpx;

					.part {
						width: 80rpx;
						height: 40rpx;
						line-height: 40rpx;
						color: #666;
						font-size: 22rpx;
						margin-right: 10rpx;
						background-color: #f9f8f8;
						border-radius: 10rpx;
						text-align: center;
					}
				}
			}
		}
	}

	.category {
		width: 100%;
		background-color: #fff;
		position: relative;
		z-index: 20;
		overflow: hidden;
		top: 88rpx;

		.item {
			float: left;
			width: 20%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding-top: 12rpx;

			.icon {
				float: left;
				width: 80rpx;
				height: 80rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				float: left;
				width: 100%;
				height: 48rpx;
				line-height: 48rpx;
				color: #666;
				font-size: 24rpx;
				text-align: center;
			}
		}
	}

	.tabbar_top {
		width: 100%;
		height: 80rpx;
		background: #fff;
		box-shadow: 0 1px 4px 0 rgba(0, 0, 0, .06);
		position: fixed;
		box-sizing: border-box;
		left: 0;
		top: calc(var(--status-bar-height) + 88rpx);
		z-index: 9999;

		.param_search {
			font-size: 26rpx;
			font-weight: 400;
			color: #666;
			display: flex;
			align-items: center;
			height: 78rpx;
			justify-content: space-between;
			position: relative;

			.param_item {
				flex: 1;
				height: 80rpx;
				color: #666;
				font-size: 26rpx;

				.text {
					display: block;
					max-width: 130rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					margin-left: 30rpx;
				}

				.icon-caret-down {
					font-size: 28rpx;
					color: #ccc;
				}
			}

			.screen {
				width: 150rpx;
				color: #666;
				font-size: 26rpx;
				position: relative;
				height: 80rpx;

				&::before {
					display: block;
					content: "";
					width: 2rpx;
					height: 24rpx;
					background: #d8d8d8;
					border-radius: 2rpx;
					position: absolute;
					left: 0;
					top: 50%;
					-webkit-transform: translateY(-50%);
					transform: translateY(-50%);
				}
			}

			.filter-box {
				width: 100vw;
				height: 0px;
				overflow: hidden;
				top: 80rpx;
				right: 0;
				background-color: rgba(#333, .4);
				position: absolute;
				z-index: 9;
				transition: all .5s;

				.where-cnt {
					margin-left: 20%;
					width: 80%;
					height: 100%;
					background-color: #fff;

					.sort-where {
						width: 100%;
						height: 100%;
						padding: 0 20rpx;
						box-sizing: border-box;

						.btns {
							padding: 30rpx 0 45rpx;
							width: 100%;

							button {
								height: 80rpx;
								background: #f6f6f6;
								border-radius: 40rpx;
								color: #666;
								font-size: 30rpx;
								margin: 0;
								line-height: 80rpx;

								&::after {
									border: none;
								}

								&:first-child {
									width: 180rpx;
									background: #f6f6f6;
									color: #666;
									margin: 0;
								}

								&:last-child {
									color: #fff;
									width: 350rpx;
									background: #aa8050;
									margin-left: 20rpx;
								}
							}
						}

						.line {
							.title {
								padding: 30rpx 0 20rpx !important;
								font-size: 28rpx;
								text-align: left;
								line-height: 30rpx;
							}

							.lbls {
								display: flex;
								padding-bottom: 30rpx;

								input {
									width: 200rpx;
									height: 60rpx;
									border: 2rpx solid #ccc;
									border-radius: 10rpx;
									padding: 0 16rpx;
									box-sizing: border-box;
								}

								view {
									width: 30rpx;
									height: 2rpx;
									background-color: #c0c0c0;
									margin: 0 20rpx;
								}
							}

							.check {
								color: #aa8050;
								background: #fdebff;
								border: 2rpx solid #aa8050;
							}
						}
					}
				}

				.service-cnt {
					width: 100%;
					height: 50vh;
					background-color: #ffffff;
					box-sizing: border-box;
					padding: 10px 0 0;

					.btn {
						width: 100%;
						height: 88rpx;
						border-top: 2rpx solid #eee;

						>view {
							flex: 1;
							text-align: center;
							line-height: 88rpx;
							height: 88rpx;
							font-size: 24rpx;

							&:last-child {
								background-color: #aa8050;
								color: #fff;
							}
						}
					}

					.scroll-view {
						width: 100%;
						height: calc(50vh - 108rpx);
						flex-wrap: wrap;
						text-align: left;
						padding: 0 20rpx;
						box-sizing: border-box;

						.scroll-view-item {
							display: inline-block;
							width: calc(33.3% - 16rpx);
							height: 50rpx;
							line-height: 50rpx;
							background: #f8f8f8;
							margin-right: 19rpx;
							color: #666;
							text-align: center;
							font-size: 24rpx;
							box-sizing: border-box;
							overflow: hidden;
							border-radius: 6rpx;

							&:nth-child(3n + 3) {
								margin-right: 0rpx;
							}
						}

						.item-check {
							background: #eee6dc;
							color: #aa8050;
						}
					}
				}

				.filter-cnt {
					width: 100%;
					background-color: #fff;

					>view {
						text-align: left;
						width: 100%;
						height: 80rpx;
						line-height: 80rpx;
						color: #666;
						font-size: 24rpx;
						overflow: hidden;
						position: relative;
						box-sizing: border-box;
						padding: 0 30rpx;
						border-bottom: 2rpx solid #f8f8f8;
					}

					.check-text {
						color: #aa8050;
					}
				}
			}

			.active-filter-box {
				height: calc(100vh - 160rpx) !important;
			}
		}
	}
</style>
